<template>
  <div id="AsnDetailList">
    <v-tableTitle :btnConfig="btnConfig"
                  :tableSelectData="selectData"
                  :title="$t('config.systemCodeList')"
                  @backList="backList"
                  @newCreate="newCreate"
                  @del="del"></v-tableTitle>

    <div class="detail">
      <component :data="{detailData,argument}"
                 :is="currentComponent"></component>
    </div>
  </div>

</template>

<script>
import tableTitle from "commons/TableTitle";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "AsnDetailList",
  mixins: [baseMixin],
  data () {
    return {
      newFlag: false,
      detailFlag: false,
      detailNew: false,
      argument: {},
      detailData: {},
      selectData: [],
      menuData: [
        { label: this.$t('bill.detail'), index: "2" },
      ],
      detailNav: "1",
      componentConfig: [
        {
          name: "Table",
          label: this.$t('config.tableDetail'),
          component: () => import('./page/Table.vue')
        },
        {
          name: "Detail",
          label: this.$t('bill.detail'),
          component: () => import('./page/Detail.vue')
        },
      ],
    }
  },
  computed: {
    btnConfig () {
      if (this.detailNav == "1") {
        if (!this.$store.state.wms.includes('wmwhse')) {
          return [
            { label: this.$t('common.create'), certigier: this.$parent.newFlag||(!this.btnPermNameList.includes('EN02050105')&&!this.btnPermNameList.includes('WM03080105')), invalid: "newCreate" },
            { label: this.$t('common.delete'), certigier: this.$parent.deleteStatus||(!this.btnPermNameList.includes('EN02050106')&&!this.btnPermNameList.includes('WM03080106')), disabled: true, invalid: "del" },
          ]
        } else {
          return [
            { label: this.$t('common.create'), certigier: this.$parent.showNewBtn||(!this.btnPermNameList.includes('EN02050105')&&!this.btnPermNameList.includes('WM03080105')), invalid: "newCreate" },
            { label: this.$t('common.delete'), certigier: this.$parent.deleteStatus||(!this.btnPermNameList.includes('EN02050106')&&!this.btnPermNameList.includes('WM03080106')), disabled: true, invalid: "del" },
          ]
        }

      } else if (this.detailNav == "2") {
        return [
          { label: this.$t('config.returnList'), certigier: !this.btnPermNameList.includes('EN02050107')&&!this.btnPermNameList.includes('WM03080107'),  invalid: "backList" },
        ]
      }
      return []
    },
    currentComponent () {
      return this.componentConfig[this.detailNav - 1].component;
    }
  },
  methods: {
    newCreate () {
      this.detailData = {
        sourceversion: 0,
        editable: "1",
        active: "1",
        sequence: 1000,
      };
      this.detailNew = true;
      this.detailNav = "2";
    },
    async del (data) {
      try {
        let res = await this.$api.post(`/deleteCodelkup/${this.$store.state.wms}`, data);
        
          this.$message.success(res.returnMgr);
          this.$children[1].getTableData(1, {})
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //返回试图
    backList () {
      this.detailNav = '1';
    },
    setMentActive (data) {
      this.detailNav = data;
    },
    async enterDetails (data) {
      try {
        let res = await this.$api.get(`/queryCodelkupByListname/${this.$store.state.wms}/${this.argument.listname}/${data.code}`);
        
          this.detailData = res.bean;
          this.detailNav = '2';
      } catch (e) {
        this.$message.error(e);
      }

    }

  },
  mounted () {
    this.newFlag = this.$store.state.newFlag;
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.argument = data.routeData;
      this.detailData = data.detailList;
      this.detailNav = data.detailListNav;
    } else if (this.newFlag) {
      this.newFlag = true;
      this.detailData = {
        sourceversion: 0,
        editable: "1",
        active: "1",
        sequence: 1000,
      };
      this.detailNav = "2";
    } else {
      this.argument = this.$store.state.routeData;
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-navMenu": navMenu,
  },
  watch: {
    detailNav (data) {
      if (data == "2") {
        this.detailFlag = true;
      } else {
        this.detailNew = false;
        this.detailFlag = false;
      }
    },
    selectData (data) {
      if (this.$parent.permissionStatus) {
        if (!this.$store.state.wms.includes('wmwhse')) {
          if (data.length > 0) {
            this.$parent.deleteStatus = false;
          } else {
            this.$parent.deleteStatus = true;
          }
        } else {
          if (data.length > 0 && !this.$parent.showNewBtn) {
            this.$parent.deleteStatus = false;
          } else {
            this.$parent.deleteStatus = true;
          }
        }

      }
    }
  }
}
</script>

<style>
</style>
